<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateFrontsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('fronts', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            
            $table->increments('id');
            $table->float('weight');
            $table->float('bmi');
            $table->string('gi');
            $table->string('waistline');
            $table->string('hipline');
            $table->string('picture');
            $table->integer('level_id')->unsigned()->index('level_id');
            $table->integer('case_id')->unsigned()->index('case_id');
            $table->timestamps();

            $table->unique('case_id');
            
            $table->foreign('level_id')
                  ->references('id')
                  ->on('levels')
                  ->onDelete('cascade');

            $table->foreign('case_id')
                  ->references('id')
                  ->on('cases')
                  ->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('fronts');
    }
}
